home *** CD-ROM | disk | FTP | other *** search
/ Amiga Inside! / Amiga FD Inside (1995)(Ultramax).iso / berndspd / devtools / precognition / src / library / interactor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-16  |  7.2 KB  |  346 lines

  1. /* ==========================================================================
  2. **
  3. **                   Interactor.c
  4. **
  5. ** ©1991 WILLISoft
  6. **
  7. ** ==========================================================================
  8. */
  9.  
  10. #include "parms.h" /* added for proper prototyping -- EDB */
  11. #include "GraphicObject.h"
  12. #include "GraphicObjectClass.h"
  13.  
  14. #include "Interactor.h"
  15. #include "InteractorClass.h"
  16. #include "pcgWindow.h"
  17.  
  18. pcgWindow *Interactor_InteractorWindow( Interactor *self )
  19. {
  20.    return self->IaWindow;
  21. }
  22.  
  23.  
  24. void Interactor_SetInteractorWindow( Interactor *self, pcgWindow *window )
  25. {
  26.    self->IaWindow = window;
  27. }
  28.  
  29.  
  30. tPoint Interactor_Location( Interactor *self )
  31. {
  32.    return self->Location;
  33. }
  34.  
  35. tPoint Interactor_Size( Interactor *self )
  36. {
  37.    return self->Size;
  38. }
  39.  
  40. tPoint Interactor_SetLocation( Interactor  *self,
  41.                                PIXELS      LeftEdge,
  42.                                PIXELS      TopEdge )
  43. {
  44.    self->Location.x = LeftEdge;
  45.    self->Location.y = TopEdge;
  46.  
  47.    return self->Location;
  48. }
  49.  
  50. tPoint Interactor_SetSize( Interactor  *self,
  51.                            PIXELS      Width,
  52.                            PIXELS      Height )
  53. {
  54.    self->Size = AskSize( (GraphicObject *)self, Width, Height );
  55.    return self->Size;
  56. }
  57.  
  58. pcgWindow *InteractorWindow( Interactor *self )
  59. {
  60.    struct InteractorClass *class;
  61.  
  62.  
  63.    if( class = (struct InteractorClass *)self->isa )
  64.    {
  65.       if( class->InteractorWindow )
  66.          return (*class->InteractorWindow)( self );
  67.    }
  68.    else
  69.       return NULL;
  70. }
  71.  
  72.  
  73. void SetInteractorWindow( Interactor *self, pcgWindow *window )
  74. {
  75.    struct InteractorClass *class;
  76.  
  77.  
  78.    if( class = (struct InteractorClass *)self->isa )
  79.    {
  80.       if( class->SetInteractorWindow )
  81.          (*class->SetInteractorWindow)( self, window );
  82.    }
  83. }
  84.  
  85.  
  86.  
  87. Gadget *FirstGadget( Interactor *self )
  88. {
  89.    struct InteractorClass *class;
  90.  
  91.  
  92.    if( class = (struct InteractorClass *)self->isa )
  93.    {
  94.       if( class->FirstGadget )
  95.          return (*class->FirstGadget)( self );
  96.    }
  97.    else
  98.       return NULL;
  99. }
  100.  
  101.  
  102. USHORT nGadgets( Interactor *self )
  103. {
  104.    struct InteractorClass *class;
  105.  
  106.  
  107.    if( class = (struct InteractorClass *)self->isa )
  108.    {
  109.       if( class->nGadgets )
  110.          return (*class->nGadgets)( self );
  111.    }
  112.    else
  113.       return 0;
  114. }
  115.  
  116.  
  117. ULONG IDCMPFlags( Interactor *self )
  118. {
  119.    ULONG flags = 0;
  120.    struct InteractorClass *class;
  121.  
  122.  
  123.    if( class = (struct InteractorClass *)self->isa )
  124.    {
  125.       if( class->IDCMPFlags )
  126.          flags = (*class->IDCMPFlags)( self );
  127.    }
  128.    return flags;
  129. }
  130.  
  131.  
  132.  
  133. USHORT ClaimEvent( Interactor    *self,
  134.                    IntuiMessage *event )
  135. {
  136.    USHORT claimed = 0;
  137.    struct InteractorClass *class;
  138.  
  139.  
  140.    if( class = (struct InteractorClass *)self->isa )
  141.    {
  142.       if( class->ClaimEvent )
  143.          claimed = (*class->ClaimEvent)( self, event );
  144.    }
  145.    return claimed;
  146. }
  147.  
  148.  
  149. USHORT Respond( Interactor    *self,
  150.                 IntuiMessage *event )
  151. {
  152.    USHORT response = 0;
  153.    struct InteractorClass *class;
  154.  
  155.  
  156.    if( class = (struct InteractorClass *)self->isa )
  157.    {
  158.       if( class->Respond )
  159.          response = (*class->Respond)( self, event );
  160.    }
  161.    return response;
  162.  
  163. }
  164.  
  165. void Refresh( Interactor  *self )
  166. {
  167.    struct InteractorClass *class;
  168.  
  169.    if( class = (struct InteractorClass *)self->isa )
  170.    {
  171.       if( class->Refresh )
  172.          (*class->Refresh)( self );
  173.    }
  174.  
  175. }
  176.  
  177.  
  178. BOOL EnableIactor( Interactor *self,
  179.              BOOL       enable )
  180. {
  181.    BOOL enabled = 0;
  182.    struct InteractorClass *class;
  183.  
  184.  
  185.    if( class = (struct InteractorClass *)self->isa )
  186.    {
  187.       if( class->EnableIactor )
  188.          enabled = (*class->EnableIactor)( self, enable );
  189.    }
  190.    return enabled;
  191.  
  192. }
  193.  
  194.  
  195. BOOL isEnabled( Interactor *self  )
  196. {
  197.    BOOL enabled = 0;
  198.    struct InteractorClass *class;
  199.  
  200.  
  201.    if( class = (struct InteractorClass *)self->isa )
  202.    {
  203.       if( class->isEnabled )
  204.          enabled = (*class->isEnabled)( self );
  205.    }
  206.    return enabled;
  207.  
  208. }
  209.  
  210.  
  211.  
  212. BOOL Activate( Interactor *self,
  213.                BOOL       activate )
  214. {
  215.    BOOL active = 0;
  216.    struct InteractorClass *class;
  217.  
  218.  
  219.    if( class = (struct InteractorClass *)self->isa )
  220.    {
  221.       if( class->Activate )
  222.          active = (*class->Activate)( self, activate );
  223.    }
  224.    return active;
  225.  
  226. }
  227.  
  228.  
  229. BOOL isActive( Interactor *self )
  230. {
  231.    BOOL active = 0;
  232.    struct InteractorClass *class;
  233.  
  234.    if( class = (struct InteractorClass *)self->isa )
  235.    {
  236.       if( class->isActive )
  237.          active = (*class->isActive)( self );
  238.    }
  239.    return active;
  240. }
  241.  
  242.  
  243. void Interactor_Refresh( Interactor *self )
  244. {
  245.    pcgWindow *window;
  246.  
  247.    /* If the subclasses have not redefined this, then simply
  248.     * render it.
  249.     */
  250.  
  251.    if( window = InteractorWindow( self ) )
  252.    {
  253.       Render( (GraphicObject *)self, window->Window->RPort );
  254.    }
  255. }
  256.  
  257. void Interactor_CleanUp( Interactor *self )
  258. {
  259.    pcgWindow *w = InteractorWindow( self );
  260.  
  261.    if( w )
  262.    {
  263.       RemoveWindowPObject( w, (GraphicObject *)self );
  264.    }
  265. }
  266.  
  267.  
  268. BOOL Interactor_elaborated = FALSE;
  269.  
  270. struct InteractorClass Interactor_Class;
  271.  
  272. void InteractorClass_Init( struct InteractorClass *class )
  273. {
  274.    GraphicObjectClass_Init( (struct GraphicObjectClass *) class );
  275.    class->isa                 = GraphicObjectClass();
  276.    class->ClassName           = "Interactor";
  277.    class->CleanUp             = (void(*)(PObject *))Interactor_CleanUp;
  278.  
  279.    class->Location            = (Point(*)(GraphicObject *))Interactor_Location;
  280.    class->SetLocation         = (Point(*)(GraphicObject *, PIXELS, PIXELS))Interactor_SetLocation;
  281.    class->Size                = (Point(*)(GraphicObject *))Interactor_Size;
  282.    /* class->AskSize = NULL;*/
  283.    class->SetSize             = (Point(*)(GraphicObject *, PIXELS, PIXELS))Interactor_SetSize;
  284.    /*class->SizeFlags          = GraphicObject_SizeFlagsAll;*/
  285. /*   class->Render              = NULL;*/
  286.    class->InteractorWindow     = Interactor_InteractorWindow;
  287.    class->SetInteractorWindow  = Interactor_SetInteractorWindow;
  288. /*   class->FirstGadget         = NULL;*/
  289. /*   class->nGadgets            = NULL;*/
  290. /*   class->IDCMPFlags          = NULL;*/
  291. /*   class->ClaimEvent          = NULL;*/
  292. /*   class->Respond             = NULL;*/
  293.    class->Refresh             = Interactor_Refresh;
  294. /*   class->EnableIactor              = NULL;*/
  295. /*   class->isEnabled           = NULL;*/
  296. /*   class->Activate            = NULL;*/
  297. /*   class->isActive            = NULL;*/
  298. }
  299.  
  300.  
  301. struct InteractorClass *InteractorClass( void )
  302. {
  303.    if( ! Interactor_elaborated )
  304.    {
  305.       InteractorClass_Init( &Interactor_Class );
  306.       Interactor_elaborated = TRUE;
  307.    }
  308.  
  309.    return &Interactor_Class;
  310. }
  311.  
  312.  
  313. void Interactor_Init( Interactor *self )
  314. {
  315.    GraphicObject_Init( (GraphicObject *)self );
  316.    self->isa             = InteractorClass();
  317.    self->IaWindow        = NULL;
  318.    self->Location.x      = 0;
  319.    self->Location.y      = 0;
  320.    self->Size.x          = 0;
  321.    self->Size.y          = 0;
  322. }
  323.  
  324.  
  325. BOOL ActivateNext( Interactor *self )
  326. {
  327.    Interactor *iactor;
  328.    pcgWindow  *pwindow;
  329.  
  330.    for( iactor = self->Next; iactor != NULL; iactor = iactor->Next )
  331.       if( Activate( iactor, TRUE ) ) return TRUE;
  332.  
  333.    /* couldn't find an activatable interactor.  Try from start of chain. */
  334.    pwindow = InteractorWindow( self );
  335.    if( pwindow )
  336.    {
  337.       for( iactor = pwindow->FirstInteractor; iactor != self; iactor = iactor->Next )
  338.          if( Activate( iactor, TRUE ) ) return TRUE;
  339.  
  340.  
  341.    }
  342.  
  343.    return Activate( self, TRUE ); /* reactivate the same interactor. */
  344. }
  345.  
  346.